
$(function(){
	$('.js_techer').hover(
		function(){
			var index = $('.js_techer').index(this);
			var _tips=$('.layer_techer_1').eq(index);			
			_tips.stop().animate({
				width:195
			});
		},
		function(){
			var index = $('.js_techer').index(this);
			var _tips=$('.layer_techer_1').eq(index);
			_tips.stop().animate({
				width:0	
			},'fast');
		}
	);
	$('.change_right').live('click',function(){
		$('.u_change_left').addClass('change_left');
		$('.change_left').removeClass('u_change_left');
		var teacher_lecture = $('.teacher_lecture').css('margin-left').split('px');
		var num = Math.abs(parseInt(teacher_lecture[0]))/63;
		var js_techer = $('.js_techer').size();
		var margin_left = parseInt(teacher_lecture[0])-63;
		$('.teacher_lecture').css('margin-left',margin_left+'px');
		if(num+6==js_techer){
			$('.change_right').addClass('u_change_right');
			$('.u_change_right').removeClass('change_right');
			$('.u_change_right').unbind('click');
		}
	})
	$('.change_left').live('click',function(){
		$('.u_change_right').addClass('change_right');
		$('.change_right').removeClass('u_change_right');
		var teacher_lecture = $('.teacher_lecture').css('margin-left').split('px');
		var num = Math.abs(parseInt(teacher_lecture[0]))/63;
		var js_techer = $('.js_techer').size();
		var margin_left = parseInt(teacher_lecture[0])+63;
		$('.teacher_lecture').css('margin-left',margin_left+'px');
		if(num==1){
			$('.change_left').addClass('u_change_left');
			$('.u_change_left').removeClass('change_left');
			$('.u_change_left').unbind('click');
		}
	})
	$('.js_course').hover(
		function(){
			var index = $('.js_course').index(this);
			var _tips=$('.layer_techer_2').eq(index);
			_tips.stop().animate({
				width:195
			},'fast');
		},
		function(){
			var index = $('.js_course').index(this);
			var _tips=$('.layer_techer_2').eq(index);
			_tips.stop().animate({
				width:0	
			},'fast');
		}
	);
	
	//立即购买
	$('.js_btn_buy').click(function(){
		var top = $(this).offset().top-138;
		$('.layer_kc').css('top',+$(this).offset().top+'px');
		$('.layer_kc').animate({
			top:top+'px',
			height:'138px'
		}, 500 );
	});
	$('.del_close,.js_shop_href').click(function(){
		var top = $('.js_btn_buy').offset().top;
		$('.layer_kc').animate({
			top:top+'px',
			height:'0px'
		}, 500 );
	});
	//弃选
	$('p .btn').toggle(
		function(){
			var id = $(this).attr('id').split('_')[0];
			var price = parseInt($('#'+id+'_price').text());
			var sum_price = parseInt($('#sum_price').text());
			sum_price = sum_price-price;
			var num_course = parseInt($('#num_course').text());
			$('#'+id+'_text').addClass('t_title_cur');
			$('#'+id+'_checked').attr("checked", false);
			$('#num_course').text(num_course-1);
			$('#sum_price').text(sum_price);
			$(this).removeClass('btn_qx');
			$(this).addClass('btn_xz');
			$(this).text('选 中');
			
		},
		function(){
			var id = $(this).attr('id').split('_')[0];
			var price = parseInt($('#'+id+'_price').text());
			var sum_price = parseInt($('#sum_price').text());
			sum_price = sum_price+price;
			$('#sum_price').text(sum_price);
			$('#'+id+'_text').removeClass('t_title_cur');
			$('#'+id+'_checked').attr("checked", true);
			var num_course = parseInt($('#num_course').text());
			$('#num_course').text(num_course+1);
			$(this).removeClass('btn_xz');
			$(this).addClass('btn_qx');
			$(this).text('取 消');
		}
	);
	
	//处理单选按钮方法
	$('.js_radio li input:radio').live('click',function(){
		var radio_text = $(this).next('span').text();
		$('#comment_content').attr('value',radio_text);
	});
	//tab切换
	$('.js_tab_tit_new li').click(function(){
		if(!$(this).hasClass('button')){
			var index = $(this).index();
			$(this).addClass('current').siblings().removeClass('current');
			var li = $('.comments_list_body');
			for(var i = 0;i<li.length;i++){
				if(i==index){
					$(li[i]).removeClass('hover-content');
				}else{
					$(li[i]).addClass('hover-content');
				}
			}
		}
		
	});
	//有效时间
	$('.js_time_href').toggle(
		function(){
			$('.js_time_text').show();
		},
		function(){
			$('.js_time_text').hide();
		}
	);
	
})
function add_num(id){
	var num = parseInt($('.js_add_num_'+id).text());
	num  = num+1;
	$('.js_add_num_'+id).text(num)
}
function detle_num(id){
	var num = parseInt($('.js_detle_num_'+id).text());
	num  = num-1;
	$('.js_detle_num_'+id).text(num)
}
//收藏
function add_course(str,id){
	var course_id= id;
		$.ajax({
			url :'/course/addFavorite/'+course_id,
			type:'post',
			dataType:'html',
			success: function (msg) {
				$('#js_free_win').hide();
				$('#js_winhtml').show();
				if(msg==0){
					window.location.href="/users/logReg/"+str;
				}else{
					$('#js_title_add').text(msg);
					var winTop = ($(window).height()/2)-(140/2)+$(document).scrollTop();
					var winLeft = Math.abs($(document).width()-280)/2;
					$('#js_favoriteAdd').css('top',winTop+'px');
					$('#js_favoriteAdd').css('left',winLeft+'px');
					$('#js_favoriteAdd').show();
					$('.closeBtn,.js_favoriteAdd_btn').click(function(){
						$('#js_favoriteAdd').hide();
					});
				}
			}
		});
		
}
function freeCourseAdd (str,course_id) {
	$.ajax({
		url :'/course/addFreecourse/'+course_id,
		type:'post',
		dataType:'html',
		success: function (msg) {
			if (msg == 0){
				window.location.href = "/users/logReg/"+str;
			}
			else if (msg == 1) {
				window.location.href = "http://i.xueersi.com/MyFreeCourses/";
			}else{
				$('#js_winhtml').hide();
				$('#js_free_win').text(msg);
				$('#js_free_win').show();
				var winTop = ($(window).height()/2)-(140/2)+$(document).scrollTop();
					var winLeft = Math.abs($(document).width()-280)/2;
					$('#js_favoriteAdd').css('top',winTop+'px');
					$('#js_favoriteAdd').css('left',winLeft+'px');
					$('#js_favoriteAdd').show();
					$('.closeBtn,.js_favoriteAdd_btn').click(function(){
						$('#js_favoriteAdd').hide();
				});
				
			}
		}
	});
}; 